﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace Infrastructure.Shell
{
    public partial class ShellForm : Form
    {
        public ShellForm()
        {
            InitializeComponent();
            FloatWindow.MainWindow = this;
            // restoring and saving shell form position
            RestoreWindow();
            FormClosing +=
                delegate(object sender, FormClosingEventArgs e)
                {
                    if (!e.Cancel)
                    {
                        Properties.Settings.Default.WindowWidth = Width;
                        Properties.Settings.Default.WindowHeight = Height;
                        Properties.Settings.Default.WindowLocationX = Location.X;
                        Properties.Settings.Default.WindowLocationY = Location.Y;
                        Properties.Settings.Default.WindowState = Convert.ToString(WindowState);
                        Properties.Settings.Default.Save();
                        //Save at [C]:\Documents and Settings\[user]\Local Settings\Application Data\[Company]\[exe]\[AssemblyVersion]\user.config
                    }
                };
        }

        /// <summary>
        /// Gets a reference for the application statusbar (<see cref="StatusStrip"/>) object.
        /// </summary>
        internal ToolStripPanel MainStatusStripPanel
        {
            get { return toolStripContainer.BottomToolStripPanel; }
        }
        internal StatusStrip DefaultStatusStrip
        {
            get { return this.mainStatusStrip; }
        }
        internal ToolStripPanel MainToolStripPanel
        {
            get { return toolStripContainer.TopToolStripPanel; }
        }

        #region Methods
        private void RestoreWindow()
        {
            if (Properties.Settings.Default.WindowHeight == 0 || Properties.Settings.Default.WindowWidth == 0)
                return;
            Height = Math.Max(Properties.Settings.Default.WindowHeight, Properties.Settings.Default.WindowHeightMin);
            Width = Math.Max(Properties.Settings.Default.WindowWidth, Properties.Settings.Default.WindowWidthMin);
            int X = Math.Max(Properties.Settings.Default.WindowLocationX, 0),
                Y = Math.Max(Properties.Settings.Default.WindowLocationY, 0);
            Point windowPoint = new Point(X, Y);
            Location = windowPoint;
            switch (Properties.Settings.Default.WindowState)
            {
                case "Normal":
                    StartPosition = FormStartPosition.Manual;
                    WindowState = FormWindowState.Normal;
                    break;
                case "Maximized":
                    StartPosition = FormStartPosition.Manual;
                    WindowState = FormWindowState.Maximized;
                    break;
                default:
                    StartPosition = FormStartPosition.WindowsDefaultLocation;
                    WindowState = FormWindowState.Normal;
                    break;
            }
        }
        #endregion
    }
}
